package ikelib;


public class MiscTools {
	public double Max;
	public double Min;
	
	public MiscTools(){
	}
	// きりのいい数字に丸める
	// digit: 有効桁数
	// bigger: true=切り上げする
	public static double round(double d,int digit){
		String fmt = String.format("%%%d.%de",digit,digit-1);
		String st =  String.format(fmt,d);
		double ret = Double.valueOf(st);
		return ret;
	}
	public void round(double max,double min,int digit){
		double span = max - min;
		int digspan = (int)Math.log10(Math.abs(span));
		int dignum  = (int)Math.log10(Math.abs(min));
		int dig = dignum - digspan;
		dig += digit;
		Max = round(max,dig);
		Min = round(min,dig);
	}
	
	public static void main(String[] args){
		double d[] = {-123.456,-12.345,12.345,0.00123,0.0};
		
		int digit=4;
		for(int i=0;d[i]!=0.0;i++){
			double d2 = round(d[i],digit);
			System.out.println(String.format("%f , %d-> %f",d[i],digit,d2));
		}
		return ;
	}
}
